
*******************************************
******			non-dyadic 			*******
*******************************************



clear all
	
cd "${data}"	
		
use cses_imd.dta, clear

gen daysafter = IMD1014_1 if IMD1014_1<363
drop if daysafter==.

rename IMD1006_NAM country 
rename IMD1004 election 

keep if country=="Australia" | country=="Austria" | country=="Belgium" | country=="Canada" | country=="Denmark" | country=="Finland" | country=="France" | country=="Germany" | country=="Greece" | country=="Iceland" | country=="Ireland" | country=="Italy" | country=="Japan" | country=="Netherlands" | country=="New Zealand" | country=="Norway" | country=="Portugal" | country=="Spain" | country=="Sweden" | country=="Switzerland" | country=="Great Britain" | country=="United States of America" 


*These are problematic surveys that we identified:

drop if election=="DNK_2001" | election=="FIN_2003" | election=="FRA_2002" | election=="GRC_2012" | election=="ISL_2007" | election=="ITA_2006" | election=="JPN_2004" | election=="NOR_2001" | election=="PRT_2005"
 
drop if country=="Japan"



rename IMD3007_*? IMD3007_#, renumber	// party placement by voters
recode IMD3007_* (95/99=.)

rename IMD5012_*? IMD5012_#, renumber // expert placement of parties
recode IMD5012_* (95/99=.)


gen accuracypartyA = abs(IMD3007_1 - IMD5012_1)	// party A accuracy
gen accuracypartyB = abs(IMD3007_2 - IMD5012_2)	// party B accuracy
gen accuracypartyC = abs(IMD3007_3 - IMD5012_3)	// party C accuracy
gen accuracypartyD = abs(IMD3007_4 - IMD5012_4)	// party D accuracy
gen accuracypartyE = abs(IMD3007_5 - IMD5012_5)	// party E accuracy
gen accuracypartyF = abs(IMD3007_6 - IMD5012_6)	// party F accuracy
gen accuracypartyG = abs(IMD3007_7 - IMD5012_7)	// party G accuracy
gen accuracypartyH = abs(IMD3007_8 - IMD5012_8)	// party H accuracy
gen accuracypartyI = abs(IMD3007_9 - IMD5012_9)	// party I accuracy

egen accuracyindex =rowmean(accuracypartyA accuracypartyB accuracypartyC accuracypartyD accuracypartyE accuracypartyF accuracypartyG accuracypartyH accuracypartyI) 		// this is an index based on accuracy of each party position


encode country, generate(country_)
encode election, generate(election_)


gen female =.
replace female = 1 if IMD2002==2
replace female = 0 if IMD2002==1

gen education = IMD2003 
replace education = . if education > 4 
label define education 0"no education" 1"primary or lower secondary" 2"higher secondary" 3"post-secondary" 4"university" 
label values education education


gen labourstatus = .
replace labourstatus = 1 if IMD2014==00 | IMD2014==01 | IMD2014==02 | IMD2014==03 // 00=employed, 01=employed
replace labourstatus = 2 if IMD2014==05 // unemployed 
replace labourstatus = 4 if IMD2014==07 // retired
replace labourstatus = 3 if IMD2014==06 // student 
replace labourstatus = 5 if IMD2014==09 // permenantly disabled 
replace labourstatus = 6 if IMD2014==04 | IMD2014==08 | IMD2014==10 | IMD2014==11 | IMD2014==12 // 4=helping a family member, 8=homemaker, home duties, 10=others, not in labour market, 11=on temporary job leave, 12= civil/military service 
label define labourstatus 1"employed" 2"unemployed" 3"student" 4"retired" 5"permanently disabled" 6"other"
label values labourstatus labourstatus

replace IMD2007 = . if IMD2007>4
rename IMD2007 ruralurban
label define ruralurban 1"village" 2"small town" 3"suburbs of large city" 4"large city"
label values ruralurban ruralurban

gen age = IMD2001_1 if IMD2001_1<121   // continous


gen income = IMD2006
replace income = . if IMD2006>5
label define income 1"lowest quantile" 2"second quantile" 3"third quantile" 4"fourth quantile" 5"highest quantile"
label values income income

eststo m1_CSES_nondyadic: mixed accuracyindex daysafter || country_: || election_: 
eststo m2_CSES_nondyadic: mixed accuracyindex daysafter age i.education i.labourstatus i.income i.ruralurban || country_: || election_: 

cd "${tables}"	
 esttab m1_CSES_nondyadic m2_CSES_nondyadic  using tableK1.tex , b(3) se(3) nogap transform(ln*: exp(2*@) 2*exp(2*@)) label mlabels ("Model 1" "Model 2")
